using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WordEveryDay
{
    public partial class Form1 : Form
    {
        
        private Random random = new Random();
        public string answer = "";
        public bool flag =false;
        public Form1()
        {
            InitializeComponent();
            this.Text = "WordHelper";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(DBHelper.connectDB())
            MessageBox.Show("成功获取数据资源！","提示");
            flag = true;
            button2.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (flag == false) MessageBox.Show("请先连接数据库!", "警告");
            else
            {
                textBox1.Text = "";
                textBox3.Text = "";
                int num = random.Next(0, DBHelper.dataSet.Tables[0].Rows.Count);
                textBox2.Text = DBHelper.dataSet.Tables[0].Rows[num][1].ToString();
                answer = DBHelper.dataSet.Tables[0].Rows[num][0].ToString();
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (flag == false) MessageBox.Show("请先连接数据库", "警告");
            else
            {
                if (textBox1.Text != answer) MessageBox.Show("答案错误!", );
                else MessageBox.Show("答对了！");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (flag == false) MessageBox.Show("请先连接数据库", "警告");
            else
            {
                textBox3.Text = answer;
            }
        }
    }
}